package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {


   /*
        reportDate:null,//报告日期
        todayNewMember :0,//今日新增会员数
        totalMember :0,//总会员数
        thisWeekNewMember :0,//本周新增会员数
        thisMonthNewMember :0,//本月新增会员数
        todayOrderNumber :0,//今日预约数
        todayVisitsNumber :0,//今日到诊数
        thisWeekOrderNumber :0,//本周预约数
        thisWeekVisitsNumber :0,//本周到诊数
        thisMonthOrderNumber :0,//本月预约数
        thisMonthVisitsNumber :0,//本月到诊数
        hotSetmeal ://显示4个热门套餐
    */

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderMapper orderMapper;
    @Override
    public Map getBusinessReport() throws Exception {

        //获取今日日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一日期
        String thisWeekMonday =  DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月一号日期
        String firstDay4ThisMonth =  DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //今日新增会员数
        Integer todayNewMember = memberMapper.findTodayNewMember(today);

        //总会员数
        Integer totalMember = memberMapper.findTotalMember();

        //本周新增会员数
        Integer thisWeekNewMember = memberMapper.findNewMemberAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember =  memberMapper.findNewMemberAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber = orderMapper.findTodayOrderNumber(today);

        //今日到诊数
        Integer todayVisitsNumber = orderMapper.findTodayVisitsNumber(today);

        //本周预约数
        Integer thisWeekOrderNumber = orderMapper.findOrderNumberAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber = orderMapper.findOrderNumberAfterDate(firstDay4ThisMonth);

        //本周到诊数
        Integer thisWeekVisitsNumber = orderMapper.findVisitsNumberAfterDate(thisWeekMonday);

        //本月到诊数
        Integer thisMonthVisitsNumber = orderMapper.findVisitsNumberAfterDate(firstDay4ThisMonth);

        //查询四个最热门的套餐
        List<Map> hotSetmeal = orderMapper.findTotSetmeal();

        //创建map,封装页面所需的数据
        Map<String,Object> map = new HashMap();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        return map;
    }


}
